package com.sxdz.config

import groovy.transform.CompileStatic
import groovy.transform.TypeChecked
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage
import me.chanjar.weixin.mp.api.WxMpService
import me.chanjar.weixin.mp.api.WxMpServiceImpl
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.PropertySource
import org.springframework.context.annotation.PropertySources
import org.springframework.core.env.Environment

/**
 * Created by zb on 2015/6/15.
 */

@CompileStatic
@TypeChecked
@Configuration
@PropertySource("classpath:global.properties")
/*@PropertySources(@PropertySource("classpath:global.properties"))*/
class WeiXinConfig {

    @Autowired
    private Environment env

    @Bean
    WxMpInMemoryConfigStorage wxConfig() {
        new WxMpInMemoryConfigStorage(
                appId: env.getProperty("weixin.appid"),
                secret: env.getProperty("weixin.appsecret"),
                token: env.getProperty("weixin.token")
        )
    }

    @Bean
    WxMpService wxMpService(){
        new WxMpServiceImpl(
                wxMpConfigStorage: wxConfig()
        )
    }
}
